function XYZ = lla2ECEF(lla)
lon = lla(1);
lat = lla(2);
alt = lla(3);

% WGS84 ellipsoid parameters
a = 6378137; % semimajor axis (m)
b = 6356752.314245; % semiminor axis (m)
f = (a - b) / a; % flattening

% Convert LLA to ECEF
N = a / sqrt(1 - f^2 * sin(lat)^2);
X = (N + alt) * cos(lat) * cos(lon);
Y = (N + alt) * cos(lat) * sin(lon);
Z = (N * (1 - f^2) + alt) * sin(lat);
XYZ = [X;Y;Z];
end